<?php
// 保存博客内容
session_start();
$user= $_SESSION['user']?$_SESSION['user']:false;
if(!$user){
	exit(json_encode(array('code'=>1,'msg'=>'请先登录后再发表')));
}

$data['uid'] = $user['uid'];
$data['title'] = $_POST['title'];
$data['cid'] = $_POST['cid'];
$data['contents'] = htmlspecialchars($_POST['msg']);
$data['add_time'] = time();

if(!$data['title']){
	exit(json_encode(array('code'=>1,'msg'=>'标题不能为空')));
}
if(!$data['contents']){
	exit(json_encode(array('code'=>1,'msg'=>'内容不能为空')));
}

require_once $_SERVER['DOCUMENT_ROOT'].'/myblog1/lib/Db.php';
$db = new Db();
$id = $db->table('article')->insert($data);
if(!$id){
	exit(json_encode(array('code'=>1,'msg'=>'博客保存失败')));
}
exit(json_encode(array('code'=>0,'msg'=>'博客发表成功')));